package com.rest.demo.controller;

import com.rest.demo.config.properties.InfoProperties;
import com.rest.demo.response.ResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.rest.demo.dto.User;

import javax.validation.Valid;
import java.util.Map;
import java.util.HashMap;

/**
 * @author Administrator
 * @decription
 * @Date 2017-11-10 14:30
 */
@RestController
public class HelloController {

    private static Logger logger = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    private InfoProperties infoProperties;

    @PostMapping(value = "/hello")
    public ResponseEntity hello() {
        return new ResponseEntity().success();
    }

    @PostMapping(value = "/user")
    public ResponseEntity user(@RequestBody @Valid User user) {
        return new ResponseEntity().success(user);
    }

    @PostMapping(value = "/info")
    public ResponseEntity info() {
        String name = infoProperties.getName();
        int age = infoProperties.getAge();
        String address = infoProperties.getAddress();
        String sex = infoProperties.getSex();
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("name",name);
        result.put("age",age);
        result.put("address",address);
        result.put("sex",sex);
        return new ResponseEntity().success(result);
    }
}
